import java.util.PrimitiveIterator;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-10-10
 * Time: 16:42
 */
public class TestDemo {
    //堆是一颗完全二叉树 - 优先级队列 - 堆来实现完全二叉树
    //每颗二叉树的根节点都小于左右孩子节点 - 小根堆/最小堆
    //反之为大根堆/最大堆

    public static void main1(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();

        //每次入队的时候，都得保证当前是大堆或者小堆
        priorityQueue.offer(12);
        priorityQueue.offer(3);
        priorityQueue.offer(15);

        //保证每次弹出后，也得保证是小堆或者大堆
        System.out.println(priorityQueue.peek());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());

    }

    public static void main(String[] args) {
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        TestHeap testHeap = new TestHeap();
        testHeap.createHeap(array);
        System.out.println();
        testHeap.offer(80);
        System.out.println();
        System.out.println(testHeap.poll());
        System.out.println(testHeap.poll());
    }
}
